/*******************************************************************************
 * 文件名: FileUploadProgressListener.java
 * 描    述: 文件上传进度
 * 创建人: Dean Huang(hudi-112@163.com)
 * 日　期: 2017-12-22
 * 描　述: 文件描述
 * 版　本: 1.0
 *******************************************************************************/

package com.z1.core.upload;

import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.ProgressListener;

import com.z1.core.utils.Utils;

public class FileUploadProgressListener implements ProgressListener {

	private HttpSession session = null;
	
	public FileUploadProgressListener() {}
	public FileUploadProgressListener(HttpSession session) {
		this.session = session;
		FileUploadProgress progress = new FileUploadProgress();
		session.setAttribute(Utils.SESSION_PARAM_FILEUPLOAD_PROGRESS, progress);
	}
	
	@Override
	public void update(long bytesRead, long contentLength, int items) { 
		FileUploadProgress progress = (FileUploadProgress)session.getAttribute(Utils.SESSION_PARAM_FILEUPLOAD_PROGRESS);
		progress.setBytesRead(bytesRead);
		progress.setContentLength(contentLength);
		progress.setItems(items);
		if (null != session) {
			session.setAttribute(Utils.SESSION_PARAM_FILEUPLOAD_PROGRESS, progress);
		}
	}

}
